package com.example.coursaccino;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ModelDbHelper extends SQLiteOpenHelper {

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "Coursaccino.db";

    Model mdl = null;
    
    public ModelDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        mdl = new Model();
    }
    
    public void onCreate(SQLiteDatabase db) {
    	System.out.println("Tables created");
        mdl.createTables(db);
    }
    
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // This database is only a cache for online data, so its upgrade policy is
        // to simply to discard the data and start over
    	mdl.deleteTables(db);
    	onCreate(db);
    }
    
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }
    
    public Model getModel () {
    	return this.mdl;
    }
}